package com.nuaa.dao.base.impl;

import java.io.Serializable;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.jdbc.core.JdbcTemplate;
import com.nuaa.dao.base.inter.IBaseDao;

public class BaseDaoImpl<T,ID extends Serializable> implements IBaseDao<T, ID>{
	@PersistenceContext
	private EntityManager em;
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	/**
	 * 保存一个实体类 
	 */
	public void save(T entity) {
		this.em.persist(entity);
	}
	/**
	 * 移除一个实体类
	 */
	public void remove(T entity) {
		this.em.remove(entity);
	}
	/**
	 * 根据id删除实体类
	 */
	public void remove(Class<T> entityClass, ID id) {
		this.em.remove(this.em.getReference(entityClass, id));
	}
	/**
	 * 更新一个实体类
	 */
	public void update(T entity) {
		this.em.merge(entity);
	}
	
}
